#ifndef UART_H
#define UART_H

#include <driver/uart.h>
#include <driver/gpio.h>
#include <string> // For std::string

class Uart {
public:
    Uart(uart_port_t uart_num, gpio_num_t tx_pin, gpio_num_t rx_pin, int baud_rate = 115200);
    ~Uart();

    esp_err_t begin();
    int read(uint8_t* data, uint32_t len, uint32_t timeout_ms);
    int write(const uint8_t* data, uint32_t len);
    // Overloaded write methods
    int write(const char* str);
    int write(const std::string& str);

    void flush();

private:
    const uart_port_t uart_num_;
    gpio_num_t tx_pin_;
    gpio_num_t rx_pin_;
    int baud_rate_;
    bool initialized_;
};

#endif // UART_H